﻿#include "ParameterConsole.h"

#include <qregexp.h>
#include <qvalidator.h>
#include <qmessagebox.h>
#include "DataLimit.h"

ParameterConsole::ParameterConsole(QWidget* parent) :QDialog(parent)
{
	ui.setupUi(this);
	setFixedSize(size());
	QRegExp regExp("^(\\d+)$");
	QValidator* pattern = new QRegExpValidator(regExp, this);
	ui.lineEdit_memsAutoTestSoftware_accuracy->setValidator(pattern);
	ui.lineEdit_MEMSData_accuracy->setValidator(pattern);
	ui.lineEdit_MEMSData_interval_collection->setValidator(pattern);
	ui.lineEdit_scriptManage_interval_turnTableOperationTimeOut->setValidator(pattern);
	ui.lineEdit_turnTable_positionUpperLimit->setValidator(pattern);
	ui.lineEdit_turnTable_positionLowerLimit->setValidator(pattern);
	ui.lineEdit_turnTable_rateUpperLimit->setValidator(pattern);
	ui.lineEdit_turnTable_rateLowerLimit->setValidator(pattern);
	ui.lineEdit_turnTable_accelerationUpperLimit->setValidator(pattern);
	ui.lineEdit_turnTable_accelerationLowerLimit->setValidator(pattern);
	connect(ui.pushButton_confirm, &QPushButton::clicked, this, &ParameterConsole::accept);
	connect(ui.pushButton_cancel, &QPushButton::clicked, this, &ParameterConsole::reject);
	connect(ui.lineEdit_memsAutoTestSoftware_accuracy,&QLineEdit::editingFinished,this,&ParameterConsole::slot_editingFinished_mEMSAutoTestSoftware_accuracy);
	connect(ui.lineEdit_MEMSData_accuracy, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_mEMSData_accuracy);
	connect(ui.lineEdit_MEMSData_interval_collection, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_mEMSData_interval_collection);
	connect(ui.lineEdit_scriptManage_interval_turnTableOperationTimeOut, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_scriptManage_interval_turnTableOperationTimeOut);
	connect(ui.lineEdit_turnTable_positionUpperLimit, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_turnTable_positionUpperLimit);
	connect(ui.lineEdit_turnTable_positionLowerLimit, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_turnTable_positionLowerLimit);
	connect(ui.lineEdit_turnTable_rateUpperLimit, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_turnTable_rateUpperLimit);
	connect(ui.lineEdit_turnTable_rateLowerLimit, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_turnTable_rateLowerLimit);
	connect(ui.lineEdit_turnTable_accelerationUpperLimit, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_turnTable_accelerationUpperLimit);
	connect(ui.lineEdit_turnTable_accelerationLowerLimit, &QLineEdit::editingFinished, this, &ParameterConsole::slot_editingFinished_turnTable_accelerationLowerLimit);
}
ParameterConsole::~ParameterConsole()
{
}
int ParameterConsole::exec()
{
	ui.lineEdit_memsAutoTestSoftware_accuracy->setText(QString::number(mEMSAutoTestSoftware_accuracy));
	ui.lineEdit_MEMSData_accuracy->setText(QString::number(mEMSData_accuracy));
	ui.lineEdit_MEMSData_interval_collection->setText(QString::number(mEMSData_interval_collection));
	ui.lineEdit_scriptManage_interval_turnTableOperationTimeOut->setText(QString::number(scriptManage_interval_turnTableOperationTimeOut));
	ui.lineEdit_turnTable_positionUpperLimit->setText(QString::number(turnTable_positionUpperLimit));
	ui.lineEdit_turnTable_positionLowerLimit->setText(QString::number(turnTable_positionLowerLimit));
	ui.lineEdit_turnTable_rateUpperLimit->setText(QString::number(turnTable_rateUpperLimit));
	ui.lineEdit_turnTable_rateLowerLimit->setText(QString::number(turnTable_rateLowerLimit));
	ui.lineEdit_turnTable_accelerationUpperLimit->setText(QString::number(turnTable_accelerationUpperLimit));
	ui.lineEdit_turnTable_accelerationLowerLimit->setText(QString::number(turnTable_accelerationLowerLimit));
	return QDialog::exec();
}
void ParameterConsole::accept()
{
	mEMSAutoTestSoftware_accuracy = ui.lineEdit_memsAutoTestSoftware_accuracy->text().toInt();
	mEMSData_accuracy = ui.lineEdit_MEMSData_accuracy->text().toInt();
	mEMSData_interval_collection = ui.lineEdit_MEMSData_interval_collection->text().toInt();
	scriptManage_interval_turnTableOperationTimeOut = ui.lineEdit_scriptManage_interval_turnTableOperationTimeOut->text().toInt();
	turnTable_positionUpperLimit = ui.lineEdit_turnTable_positionUpperLimit->text().toInt();
	turnTable_positionLowerLimit = ui.lineEdit_turnTable_positionLowerLimit->text().toInt();
	turnTable_rateUpperLimit = ui.lineEdit_turnTable_rateUpperLimit->text().toInt();
	turnTable_rateLowerLimit = ui.lineEdit_turnTable_rateLowerLimit->text().toInt();
	turnTable_accelerationUpperLimit = ui.lineEdit_turnTable_accelerationUpperLimit->text().toInt();
	turnTable_accelerationLowerLimit = ui.lineEdit_turnTable_accelerationLowerLimit->text().toInt();
	QDialog::accept();
	return;
}
void ParameterConsole::slot_editingFinished_mEMSAutoTestSoftware_accuracy()
{
	dataStandardizeEditing(ui.lineEdit_memsAutoTestSoftware_accuracy, mEMSAutoTestSoftware_accuracy,DataLimit::standardizeMEMSDataAccuracy_display);
}
void ParameterConsole::slot_editingFinished_mEMSData_accuracy()
{
	dataStandardizeEditing(ui.lineEdit_MEMSData_accuracy, mEMSData_accuracy, DataLimit::standardizeMEMSDataAccuracy_save);
}
void ParameterConsole::slot_editingFinished_mEMSData_interval_collection()
{
	dataStandardizeEditing(ui.lineEdit_MEMSData_interval_collection, mEMSData_interval_collection, DataLimit::standardizeMEMSDataCollectionInterval);
}
void ParameterConsole::slot_editingFinished_scriptManage_interval_turnTableOperationTimeOut()
{
	dataStandardizeEditing(ui.lineEdit_scriptManage_interval_turnTableOperationTimeOut, scriptManage_interval_turnTableOperationTimeOut, DataLimit::standardizeScriptManageTurnTableOperationTimeOutInterval);
}
void ParameterConsole::slot_editingFinished_turnTable_positionUpperLimit()
{
	dataStandardizeEditing(ui.lineEdit_turnTable_positionUpperLimit, turnTable_positionUpperLimit, DataLimit::standardizeTurnTablePositionLimit);
	dataStandardizeUpperLimit(ui.lineEdit_turnTable_positionUpperLimit, ui.lineEdit_turnTable_positionLowerLimit);
}
void ParameterConsole::slot_editingFinished_turnTable_positionLowerLimit()
{
	dataStandardizeEditing(ui.lineEdit_turnTable_positionLowerLimit, turnTable_positionLowerLimit, DataLimit::standardizeTurnTablePositionLimit);
	dataStandardizeLowerLimit(ui.lineEdit_turnTable_positionLowerLimit, ui.lineEdit_turnTable_positionUpperLimit);
}
void ParameterConsole::slot_editingFinished_turnTable_rateUpperLimit()
{
	dataStandardizeEditing(ui.lineEdit_turnTable_rateUpperLimit, turnTable_rateUpperLimit, DataLimit::standardizeTurnTableRateLimit);
	dataStandardizeUpperLimit(ui.lineEdit_turnTable_rateUpperLimit, ui.lineEdit_turnTable_rateLowerLimit);
}
void ParameterConsole::slot_editingFinished_turnTable_rateLowerLimit()
{
	dataStandardizeEditing(ui.lineEdit_turnTable_rateLowerLimit, turnTable_rateLowerLimit, DataLimit::standardizeTurnTableRateLimit);
	dataStandardizeLowerLimit(ui.lineEdit_turnTable_rateLowerLimit, ui.lineEdit_turnTable_rateUpperLimit);
}
void ParameterConsole::slot_editingFinished_turnTable_accelerationUpperLimit()
{
	dataStandardizeEditing(ui.lineEdit_turnTable_accelerationUpperLimit, turnTable_accelerationUpperLimit, DataLimit::standardizeTurnTableAccelerationLimit);
	dataStandardizeUpperLimit(ui.lineEdit_turnTable_accelerationUpperLimit, ui.lineEdit_turnTable_accelerationLowerLimit);
}
void ParameterConsole::slot_editingFinished_turnTable_accelerationLowerLimit()
{
	dataStandardizeEditing(ui.lineEdit_turnTable_accelerationLowerLimit, turnTable_accelerationLowerLimit, DataLimit::standardizeTurnTableAccelerationLimit);
	dataStandardizeLowerLimit(ui.lineEdit_turnTable_accelerationLowerLimit, ui.lineEdit_turnTable_accelerationUpperLimit);
}
void ParameterConsole::dataStandardizeEditing(QLineEdit* qLineEdit, int defaultValue, int(* dataStandardizeFunction)(int))
{
	QString value = qLineEdit->text();
	if (value.isEmpty())
	{
		qLineEdit->setText(QString::number(mEMSAutoTestSoftware_accuracy));
		return;
	}
	int accuracy1 = value.toInt();
	qLineEdit->setText(QString::number(((*dataStandardizeFunction)(accuracy1))));
}
void ParameterConsole::dataStandardizeUpperLimit(QLineEdit* upperLimitLineEdit, QLineEdit* lowerLimitLineEdit)
{
	QString upperLimit = upperLimitLineEdit->text();
	QString lowerLimit = lowerLimitLineEdit->text();
	if (upperLimit.toInt()< lowerLimit.toInt())
	{
		upperLimitLineEdit->setText(lowerLimit);
	}
}
void ParameterConsole::dataStandardizeLowerLimit(QLineEdit* lowerLimitLineEdit, QLineEdit* upperLimitLineEdit)
{
	QString upperLimit = upperLimitLineEdit->text();
	QString lowerLimit = lowerLimitLineEdit->text();
	if (upperLimit.toInt() < lowerLimit.toInt())
	{
		lowerLimitLineEdit->setText(upperLimit);
	}
}
int ParameterConsole::getMEMSAutoTestSoftware_accuracy()
{
	return mEMSAutoTestSoftware_accuracy;
}
void ParameterConsole::setMEMSAutoTestSoftware_accuracy(int mEMSAutoTestSoftware_accuracy)
{
	this->mEMSAutoTestSoftware_accuracy = mEMSAutoTestSoftware_accuracy;
}
int ParameterConsole::getMEMSData_accuracy()
{
	return mEMSData_accuracy;
}
void ParameterConsole::setMEMSData_accuracy(int mEMSData_accuracy)
{
	this->mEMSData_accuracy = mEMSData_accuracy;
}
int ParameterConsole::getMEMSData_interval_collection()
{
	return mEMSData_interval_collection;
}
void ParameterConsole::setMEMSData_interval_collection(int mEMSData_interval_collection)
{
	this->mEMSData_interval_collection = mEMSData_interval_collection;
}
int ParameterConsole::getScriptManage_interval_turnTableOperationTimeOut()
{
	return scriptManage_interval_turnTableOperationTimeOut;
}
void ParameterConsole::setScriptManage_interval_turnTableOperationTimeOut(int scriptManage_interval_turnTableOperationTimeOut)
{
	this->scriptManage_interval_turnTableOperationTimeOut = scriptManage_interval_turnTableOperationTimeOut;
}
int ParameterConsole::getTurnTable_positionUpperLimit()
{
	return turnTable_positionUpperLimit;
}
void ParameterConsole::setTurnTable_positionUpperLimit(int turnTable_positionUpperLimit)
{
	this->turnTable_positionUpperLimit = turnTable_positionUpperLimit;
}
int ParameterConsole::getTurnTable_positionLowerLimit()
{
	return turnTable_positionLowerLimit;
}
void ParameterConsole::setTurnTable_positionLowerLimit(int turnTable_positionLowerLimit)
{
	this->turnTable_positionLowerLimit = turnTable_positionLowerLimit;
}
int ParameterConsole::getTurnTable_rateUpperLimit()
{
	return turnTable_rateUpperLimit;
}
void ParameterConsole::setTurnTable_rateUpperLimit(int turnTable_rateUpperLimit)
{
	this->turnTable_rateUpperLimit = turnTable_rateUpperLimit;
}
int ParameterConsole::getTurnTable_rateLowerLimit()
{
	return turnTable_rateLowerLimit;
}
void ParameterConsole::setTurnTable_rateLowerLimit(int turnTable_rateLowerLimit)
{
	this->turnTable_rateLowerLimit = turnTable_rateLowerLimit;
}
int ParameterConsole::getTurnTable_accelerationUpperLimit()
{
	return turnTable_accelerationUpperLimit;
}
void ParameterConsole::setTurnTable_accelerationUpperLimit(int turnTable_accelerationUpperLimit)
{
	this->turnTable_accelerationUpperLimit = turnTable_accelerationUpperLimit;
}
int ParameterConsole::getTurnTable_accelerationLowerLimit()
{
	return turnTable_accelerationLowerLimit;
}
void ParameterConsole::setTurnTable_accelerationLowerLimit(int turnTable_accelerationLowerLimit)
{
	this->turnTable_accelerationLowerLimit = turnTable_accelerationLowerLimit;
}
